package com.insight.common.mq.stream;

import lombok.Getter;
import com.insight.common.constant.CacheConstant;
import com.insight.common.mq.MessageType;
import com.insight.common.mq.RedisMqInit;

/**
 * @author JinPengDong
 * @date 2023/10/7
 */

public class RedisMqStream {

    private final String name;
    @Getter
    private final MessageType messageType;

    public RedisMqStream(String name, MessageType messageType) {
        this.name = CacheConstant.STREAM_PREFIX + name;
        this.messageType = messageType;
    }

    public String getGroup() {
        switch (messageType) {
            case publicize:
                return RedisMqInit.getCONSUMER();
            case unicast:
            default:
                return RedisMqInit.getGROUP();
        }
    }

    public String getName() {
        if (name.contains(CacheConstant.CURRENT_KEY)) {
            return name.replace(CacheConstant.CURRENT_KEY, RedisMqInit.getCONSUMER());
        }
        return name;
    }
}
